<?php
/**
 * 获取配置文件内信息
 */
namespace core\lib;
class conf{

    public static $conf;

    /**
     * 获取配置文件内对应属性信息
     * @param $name  对应属性
     * @param $file 文件名
     * @return mixed
     * @throws \Exception
     */

    public static function get($name, $file)
    {
        if (isset(self::$conf[$file])) {
            return self::$conf[$file][$name];
        } else{
            $path = CORE . '/conf/' . $file . '.php';
            if (is_file($path)) {
                $conf = include $path;
                if (isset($conf[$name])) {
                    self::$conf[$file] = $conf;
                    return $conf[$name];
                } else {
                    throw new \Exception("没有这个配置项" . $name);
                }
            } else {
                throw new \Exception("找不到配置文件" . $file);
            }
        }
    }

    /**
     * 获取配置文件内所有参数信息
     * @param $file
     * @return mixed
     * @throws \Exception
     */
    public static function all($file){

        if (isset(self::$conf[$file])) {
            return self::$conf[$file];
        } else{
            $path = CORE . '/conf/' . $file . '.php';
            if (is_file($path)) {
                $conf = include $path;
                self::$conf[$file] = $conf;
                return $conf;
            } else {
                throw new \Exception("找不到配置文件" . $file);
            }
        }
    }
}